package br.com.mtg.movethegarbage.screens;

import javax.microedition.khronos.opengles.GL10;

import br.com.mtg.movethegarbage.framework.Game;
import br.com.mtg.movethegarbage.framework.Screen;
import br.com.mtg.movethegarbage.game.Assets;
import br.com.mtg.movethegarbage.graphics.Camera2D;
import br.com.mtg.movethegarbage.graphics.SpriteManager;

public class SplashScreen extends Screen
{
	SpriteManager spriteManager;
	Camera2D cam;
	long timer;

	public SplashScreen(Game _game)
	{
		super(_game);
		spriteManager = new SpriteManager(game.getGraphics(), 1);
		cam = new Camera2D(game.getGraphics());
		timer = 0;
		multiplier = game.getGraphics().getMultiplier();
	}

	@Override
	public void update(long delta)
	{
		timer += delta;
		if (timer > 5000)
			game.setScreen(game.getStartScreen());
	}

	@Override
	public void present(long delta)
	{
		GL10 gl = game.getGraphics().getGL();
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

		spriteManager.beginDraw(Assets.tex_splash);
		spriteManager
				.drawSprite((width - 220.0F * multiplier) / 2, (height - 184.0F * multiplier) / 2, 220.0F * multiplier, 184.0F * multiplier, Assets.splash);
		spriteManager.endDraw();
	}

	@Override
	public void pause()
	{
	}

	@Override
	public void resume()
	{
		cam.setViewAndMatrices();

		game.getGraphics().initialize();

		Assets.startSound.play(0.2F);

		width = game.getGraphics().getWidth();
		height = game.getGraphics().getHeight();
		multiplier = game.getGraphics().getMultiplier();
	}

	@Override
	public void dispose()
	{
	}

}
